package com.my.screenadapter.rvcommon.ListDemo;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.my.screenadapter.Base.BaseActivity;
import com.my.screenadapter.Base.CommonAdapter;
import com.my.screenadapter.Base.ViewHolder;
import com.my.screenadapter.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

/**
 * Created by 张英杰 on 2016/11/16.
 */

public class ListFirstActivity extends BaseActivity {
    //        为RecyclerView打造通用Adapter 让RecyclerView更加好用
//        http://blog.csdn.net/lmj623565791/article/details/51118836
    @BindView(R.id.id_listview_list)
    ListView mListView;
    @BindView(R.id.id_empty_view)
    View mEmptyView;
    private List<String> mDatas = new ArrayList<>(Arrays.asList("MultiItem ListView",
            "RecyclerView",
            "MultiItem RecyclerView"));

    @Override
    protected void init() {
        mListView.setAdapter(new CommonAdapter<String>(this,
                R.layout.item_list, mDatas) {
            @Override
            protected void convert(ViewHolder viewHolder, String item, int position) {
                viewHolder.setText(R.id.id_item_list_title, item);
            }

            @Override
            public void onViewHolderCreated(ViewHolder holder, View itemView) {
                super.onViewHolderCreated(holder, itemView);
            }
        });

        mListView.setEmptyView(mEmptyView);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = null;
                switch (position) {
                    case 0:
                    default:
                        intent = new Intent(ListFirstActivity.this, MultiItemListViewActivity.class);
                        break;
                    case 1:
                        Toast.makeText(ListFirstActivity.this,"nothing ",Toast.LENGTH_LONG).show();
                        break;
                    case 2:
                        intent = new Intent(ListFirstActivity.this, MultiItemRvActivity.class);
                        break;

                }
                if (intent != null)
                    startActivity(intent);
            }
        });
    }

    @Override
    protected int initLayoutId() {
        return R.layout.activity_listfirst;
    }
}
